package shard

import (
	"math"
	"strconv"
)

//分片策略-均衡
//分片策略-均衡
type Equalize func(key Key, shardSize uint) (uint, string)

//直接long值分片均衡
func EqualizeByLong(key Key, shardSize uint) (uint, string) {
	return key.Get()
}

//long值取模分片算法
func EqualizeByLongModule(key Key, shardSize uint) (uint, string) {
	seed, _ := key.Get()
	index := uint(math.Abs(float64(seed % shardSize)))
	if index == 0 {
		return shardSize, strconv.Itoa(int(shardSize))
	} else {
		return index, strconv.Itoa(int(index))
	}
}
